<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../../../plugin/layui/css/layui.css">
    <link rel="stylesheet" href="../../../plugin/lenos/main.css">
    <script type="text/javascript" src="../../../plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="../../../plugin/layui/layui.all.js" charset="utf-8"></script>
</head>

<body>

<div class="lenos-search">
    <div class="select">
        缺陷名：
        <div class="layui-inline">
            <input class="layui-input" height="20px" id="rolename" autocomplete="off">
        </div>
        <button class="select-on layui-btn layui-btn-sm" data-type="select"><i class="layui-icon">&#xe615;</i></button>
    </div>
</div>

<!-- 表格上方按钮 -->
<div class="layui-col-md12" style="height:40px;margin-top:3px;">
    <div class="layui-btn-group">
        <button id="add" class="layui-btn layui-btn-normal" data-type="add">
            <i class="layui-icon">&#xe608;</i>提BUG
        </button>
    </div>
</div>

<!-- 数据表格 -->
<table id="list" class="layui-hide" lay-filter="bug"></table>

<!-- 表格按钮 -->
<script type="text/html" id="toolBar">
    <a class="layui-btn layui-btn-xs  layui-btn" lay-event="process">处理</a>
    <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script>

    // 表格初始化
    var table = layui.table;

    // 新增
    $("#add").click(function(){
        add();
    });

    //方法级渲染
    layui.table.render({
        id: 'list',
        elem: '#list'
        , url: '../../../pdms/bug/selectList'
        , cols: [[
            {checkbox: true, fixed: true, width: '5%'}
            , {field: 'name', title: '缺陷名称', width: '20%', sort: true}
            , {field: 'versionName', title: '发现版本', width: '10%', sort: true}
            , {field: 'createDateText', title: '创建时间', width: '10%', sort: true}
            , {field: 'createUserName', title: '创建人', width: '10%', sort: true}
            , {field: 'statusText', title: '状态', width: '10%', sort: true}
            , {field: 'finishDateText', title: '完成时间', width: '10%', sort: true}
            , {field: 'dealUserName', title: '完成人', width: '10%', sort: true}
            /*, {
                field: 'createDate',
                title: '创建时间',
                width: '20%',
                templet: '<div>{{ layui.laytpl.toDateString(d.createDate,"yyyy-MM-dd") }}</div>'
            }*/
            , {field: 'remark', title: '操作', width: '20%', toolbar: "#toolBar"}
        ]]
        , page: true
        , height: 'full-83'
    });

    //监听表格复选框选择
    table.on('checkbox(user)', function (obj) {
        //console.log(obj)
    });

    //监听工具条
    table.on('tool(bug)', function (obj) {
        var data = obj.data;
        if(obj.event === 'process'){
            process(data);
        } else if (obj.event === 'del') {
            layer.confirm('确定删除[<label style="color: #00AA91;">' + data.name + '</label>]?', function () {
                del(data.id);
            });
        } else if (obj.event === 'edit') {
            edit(data);
        }
    });

    function del(id) {
        $.post('../../../pdms/bug/remove',{id:id},function (d) {
            layer.msg(d.msg);
            layui.table.reload('list');
        },'json');
    }


    function add() {
        layer.open({
            type: 2,
            area: ['1000px', '500px'],
            title: '新增缺陷',
            content: 'add-bug.html'
        });
    }

    function edit(data) {
        window.data = data;
        layer.open({
            type: 2,
            area: ['1000px', '500px'],
            title: '编辑缺陷',
            content: 'update-bug.html'
        });
    }

    function process(data) {
        window.data = data;
        layer.open({
            type: 2,
            area: ['1000px', '500px'],
            title: '处理缺陷',
            content: 'process-bug.html'
        });
    }
</script>
</body>

</html>
